//
//  MessageDetailCell.m
//  TengyunStation
//
//  Created by Johnny on 15/9/16.
//  Copyright (c) 2015年 xingrong. All rights reserved.
//

#import "MessageDetailCell.h"
#import "MessageDetail.h"
#import "TSHeader.h"

@implementation MessageDetailCell

- (void)awakeFromNib {
    // Initialization code
    _bgView.layer.cornerRadius = 4;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(85, 0, 150, 15)];
        _timeLabel.backgroundColor = [UIColor clearColor];
        _timeLabel.textAlignment = NSTextAlignmentCenter;
        _timeLabel.font = [UIFont systemFontOfSize:13];
        _timeLabel.textColor = AssistTextColor;
        [self addSubview:_timeLabel];
        
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(8, 25, 304, 65)];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 4;
        _bgView.clipsToBounds = YES;
        [self addSubview:_bgView];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 10, 288, 15)];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textColor = MainTextColor;
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.numberOfLines = 0;
        [_bgView addSubview:_titleLabel];
        
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 35, 288, 15)];
        _contentLabel.backgroundColor = [UIColor clearColor];
        _contentLabel.textColor = AssistTextColor;
        _contentLabel.font = [UIFont systemFontOfSize:13];
        _contentLabel.numberOfLines = 0;
        [_bgView addSubview:_contentLabel];
    }
    return self;
}

- (void)reloadMessageDetailCell:(MessageDetail *)detail {
    _timeLabel.text = detail.showDay;
    CGSize titleSize = [detail.title sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(288, MAXFLOAT)];
    _titleLabel.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y, titleSize.width, titleSize.height);
    _titleLabel.text = detail.title;
    CGSize contentSize = [detail.content sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(288, MAXFLOAT)];
    _contentLabel.frame = CGRectMake(_contentLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 10, contentSize.width, contentSize.height);
    _contentLabel.text = detail.content;
    _bgView.frame = CGRectMake(_bgView.frame.origin.x, _bgView.frame.origin.y, _bgView.frame.size.width, _contentLabel.frame.origin.y + _contentLabel.frame.size.height + 10);
}

+ (float)calculateCellHeight:(MessageDetail *)detail {
    CGSize titleSize = [detail.title sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(288, MAXFLOAT)];
    CGSize contentSize = [detail.content sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(288, MAXFLOAT)];
    float height = titleSize.height + contentSize.height + 25 + 40;
    if (height < 100) {
        height = 100;
    }
    return height;
}

@end
